<template>
    <view class="content">
        <view class="nav">
            <view class="nav-i" :class="{active : type == 3}" @click="chooseNav(3)">全部订单</view>
            <view class="nav-i" :class="{active : type == 4}" @click="chooseNav(4)">我的发布</view>
        </view>
        <view class="line"></view>
        <view class="wrapper">
            <view class="item" v-for="(item, index) in list" :key="index" 
                @click="$gTo(`/mine/pages/online-order/online-details?id=${item.id}`)">
                <image :src="item.image" class="item-img" mode="aspectFill"></image>
                <view>
                    <view class="name">{{item.title}}</view>
                    <view class="sub">{{item.describes}}</view>
                    <view class="time">{{item.date}}</view>
                    <view class="down" v-if="type == 4">
                        <image :src="IMAGEURL + 'static/icon/del.png'" class="del-icon" @click.stop="del(item)"></image>
                    </view>
                </view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
        
        <view class="btn" @click="$gTo(`/mine/pages/online-order/online-create`)">
            <image :src="IMAGEURL + 'static/icon/write.png'" class="write-icon"></image>
            <view>发布信息</view>
        </view>
    </view>
</template>

<script>
    import { IMAGEURL } from '@/static/js/common.js';
    export default {
        data() {
            return {
                IMAGEURL,
                type: 3,
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
            };
        },
        onShow() {
            this.page = 1
            this.list = []
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            del(item) {
                this.$confirm('确定删除吗？',()=>{
                    this.$ajax('delete_activity', {
                    	user_token: this.$getSync('userToken'),
                        id: item.id,//活动id
                    }).then(ret => {
                    	if (ret.success == 1000) {
                    		this.$toast('删除成功')
                            setTimeout(() => {
                                this.page = 1
                                this.list = []
                                this.status = 'loadmore'
                                this.getList()
                            }, 500)
                    	} else {
                    		this.$toast(ret.msg);
                    	}
                    });
                })
            },
            
            chooseNav(num) {
                if (this.type == num) return
                this.type = num
                this.page = 1
                this.list = []
                this.status = 'loadmore'
                this.getList()
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('activity_list', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    type: this.type,//1活动 2艺术班 3实时计划全部 4实时计划我的 5未报名订单 6已报名订单
                    type_id: '',//活动分类id
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail && ret.detail.activity && ret.detail.activity.length > 0) {
            				this.list = this.list.concat(ret.detail.activity);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #fff;
    }
    .nav{
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: #fff;
    }
    .nav-i{
        width: calc(100vw / 2);
        padding: 30rpx 0;
        font-size: 28rpx;
        text-align: center;
    }
    .active{
        font-size: 32rpx;
        color: #f29700;
        border-bottom: 2rpx solid #f29700;
    }
    .line{
        width: 100vw;
        height: 20rpx;
        background-color: #f5f5f5;
    }
    .wrapper{
        padding: 20rpx 30rpx;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 30rpx 0;
    }
    .item-img{
        width: 165rpx;
        height: 165rpx;
        border-radius: 10rpx;
        margin-right: 20rpx;
    }
    .name{
        width: 500rpx;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 32rpx;
        font-weight: bold;
        padding-bottom: 20rpx;
    }
    .sub{
        font-size: 24rpx;
        color: #949494;
        width: 500rpx;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .time{
        font-size: 24rpx;
        color: #949494;
    }
    .down{
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
    .del-icon{
        width: 33rpx;
        height: 33rpx;
    }
    
    .btn{
        width: 122rpx;
        height: 122rpx;
        background-color: #f29700;
        border-radius: 20rpx;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        font-size: 22rpx;
        color: #fff;
        position: fixed;
        right: 20rpx;
        bottom: 170rpx;
        z-index: 9;
    }
    .write-icon{
        width: 39rpx;
        height: 45rpx;
        margin-bottom: 10rpx;
    }
    

</style>
